{extend name="lib/common_list" /}
{block name="title"}{/block}
{block name="css"}
{load href="/static/sys/css/common.css" /}
{load href="/static/plugins/select2/css/select2.css" /}
{load href="/static/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" /}

{load href="/static/sys/css/skin_0.css" /}
<style>
    .upfile i{padding-right:3px !important;}
    .file{ position:absolute;right:0;top:0;width:100px;height:100px;opacity:0; ilter:alpha(opacity=0);cursor:pointer;margin-bottom: 0px;margin-right: 0px; }
</style>
{/block}
{block name="javascript"}
{load  href="/static/plugins/select2/js/select2.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" /}

<script>
    $(document).ready(function () {
        $("#ok").bind("click", Save);
        $("#cancel").bind("click", function () {
            parent.layer.close(parent.layer_add_index);
        });

        /**
         * 保存内容
         */
        function Save() {
            var load_index = layer.load(0, { shade: false });

            $.ajax({
                type: 'POST',
                url: "{:url('basic_config/add')}",
                data: $("#fmNew").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.close(load_index);
                        layer.alert(data.msg, function () {
                            parent.refreshtb();
                            //window.close();
                            parent.layer.close(parent.layer_add_index);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        }

        $('#album_skin_title').select2();
        $('#applet_name').select2();
        //$('#album_button_name').select2();
    });

    /**
     * 新增图片
     */
    var layer_image_add;
    function defaultShareImg() {
        layer_image_add = layer.open({
            type: 2,
            title: "新增图片",
            area: ['70%', '90%'],
            content: "{:url('upload/image')}?tag=share_img"
        })
    }

    // 上传成功后的回调，该函数名不能写错
    function getImageUrl(res) {
        if (res.tag == 'share_img') {
            $('#default_share_img').val(res.url);
            $('#previewImg_share').attr('src', res.url);
        }
    }

    function skinValue() {
        var skin_name = $("#album_skin_title").children('option:selected').attr('album_skin_name');
        $('#album_skin_name').val(skin_name);
    }

    function musicName() {
        var album_music = $("#album_music_name").children('option:selected').attr('album_music');
        var music_id = $("#album_music_name").children('option:selected').attr('music_id');
        $('#album_music').val(album_music);
        $('#music_id').val(music_id);
    }

    function appletValue() {
        var applet_app_id = $("#applet_name").children('option:selected').attr('applet_app_id');
        $('#applet_app_id').val(applet_app_id);
    }
</script>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" id="fmNew" class="form-horizontal" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">配置名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="name" placeholder="请输入配置名称">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">绑定的小程序：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="applet_name" id="applet_name" onchange="appletValue()">
                                    <option value="">请选择小程序...</option>
                                    {volist name="applet_list" id="v"}
                                    <option value="{$v.applet_name}" applet_app_id="{$v.applet_app_id}">{$v.applet_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">小程序APP ID：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="applet_app_id" id="applet_app_id" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">相册默认模板：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="album_skin_title" id="album_skin_title" onchange="skinValue()">
                                    <option value="">请选择相册默认模板...</option>
                                    {volist name="skin_list" id="v"}
                                    <option value="{$v.title}" album_skin_name="{$v.name}">{$v.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">相册模板名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" readonly name="album_skin_name" id="album_skin_name">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">模板基础路径：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control"  name="skin_base_url" id="skin_base_url" placeholder="请输入模板基础路径，该路径和模板名拼接成相册模板url">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">相册默认音乐：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="album_music_name" id="album_music_name" onchange="musicName()">
                                    <option value="">请选择相册默认音乐...</option>
                                    {volist name="music_list" id="v"}
                                    <option value="{$v.title}" music_id="{$v.id}" album_music="{$v.mp3_url}">{$v.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">默认音乐地址：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control"  name="album_music" id="album_music" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">默认音乐MID：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control"  name="music_id" id="music_id" readonly>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">打赏：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="is_reward">
                                    {volist name="reward_list" id="v"}
                                    <option value="{$key}">{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">打赏说辞：</label>
                            <div class="col-sm-8">
                                <textarea type="text" class="form-control"  name="reward_tip" id="reward_tip"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">默认分享标题：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control"  name="default_share_title" id="default_share_title">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">默认分享图：</label>
                            <div class="col-sm-1">
                                <span id="button_img" class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;" onclick="defaultShareImg()">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 默认分享图<input type="hidden" name="default_share_img" id="default_share_img" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_share" style="height:34px;float: right;">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status">
                                    {volist name="status_list" id="v"}
                                    <option value="{$key}">{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">广告：</label>
                            <div class="col-sm-8">
                                <textarea type="text" class="form-control"  name="ad1" id="ad1"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">广告：</label>
                            <div class="col-sm-8">
                                <textarea type="text" class="form-control"  name="ad2" id="ad2"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">广告：</label>
                            <div class="col-sm-8">
                                <textarea type="text" class="form-control"  name="ad3" id="ad3"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">广告：</label>
                            <div class="col-sm-8">
                                <textarea type="text" class="form-control"  name="ad4" id="ad4"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <!--<div class="form-group">
                            <label class="col-sm-2 control-label">按钮描叙：</label>
                            <div class="col-sm-8">
                                <textarea name="desc" cols="100%" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">默认顶部导航按钮：</label>
                            <div class="col-sm-8">
                                <button type="button" class="btn btn-success" onclick="add_line()">新增一行</button>
                            </div>
                        </div>
                        <div class="form-group">
                            <fieldset style="border: 2px solid orange; margin-left: 5%; margin-right: 5%;">
                                <div class="col-sm-10" style="margin-left: 5%;">
                                    <table class="table table-hover" id="tb_top_bar" >
                                        <tr>
                                            <td><label class='control-label x85'>顶部导航按钮:</label></td>
                                            <td>
                                                <select class="form-control" name='top_button_key[]'>
                                                    <option>请选择....</option>
                                                    {volist name='button_list' id='v'}
                                                    <option value="{$v.key}">{$v.name}</option>
                                                    {/volist}
                                                </select>
                                            </td>
                                            <td><button type="button" class="btn btn-warning" onclick="$(this).parent().parent().remove()">删除</button></td>
                                        </tr>
                                    </table>
                                </div>
                            </fieldset>
                        </div>-->

                        <div id = 'hidden_input'>
                            <input type="hidden"  name="id" />
                        </div>

                        <div class="form-group">
                            <div class="col-sm-12 col-sm-offset-5">
                                <button class="btn btn-primary" id="ok" type="button">提交</button>
                                <button class="btn btn-white" id="cancel" type="button">取消</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}